<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace builder\table\util\tditems;

use builder\base\FormatOptionsTrait;
use builder\helper\App;

/**
 * 工具栏中下拉选择菜单项的类型接口
 * @author clevstn
 * @since ym2.0
 */
abstract class TDItemsType
{
    use FormatOptionsTrait;

    // 下拉菜单选项ID
    private static $_id = 0;

    /**
     * @return int
     */
    public function getId()
    {
        $class = get_class($this);
        $idPrefix = substr(strrchr($class, '\\'), 1);

        return 'TableToolbarDropdownItem_' . $idPrefix . (++self::$_id);
    }

    /**
     * @return array
     */
    abstract public function _toArray();

    /**
     * RBAC检查
     * @param string $route 路由或外链
     * @return bool
     */
    protected function checkAccess($route)
    {
        return App::rbacManager()->permissionValidate($route);
    }
}